//import java.io.*;
//import java.util.Scanner;
//
//// Press Shift twice to open the Search Everywhere dialog and type `show whitespaces`,
//// then press Enter. You can now see whitespace characters in your code.
//public class Main {
//    public static void main(String[] args) throws IOException {
//        Scanner sc=new Scanner(System.in);
//
//        FileOutputStream fileOutputStream=new FileOutputStream("d:\\data.dat");
//        String str=sc.nextLine();
//        while(!str.equals("end"))
//        {
//            fileOutputStream.write(str.getBytes());
//            fileOutputStream.write("\n".getBytes());
//            str=sc.nextLine();
//        }
//        FileInputStream fileInputStream=new FileInputStream("d:\\data.dat");
//        BufferedInputStream bufferedInputStream=new BufferedInputStream(fileInputStream);
//        int ret;
//        while((ret=bufferedInputStream.read())!=-1)
//        {
//            System.out.print((char)ret);
//        }
//    }
//}

import javax.tools.FileObject;
import java.io.*;
import java.util.Scanner;

//import java.io.BufferedReader;
//import java.io.FileReader;
//import java.io.FileWriter;
//import java.io.IOException;
//import java.util.Scanner;
//
//public class Main {
//    public static void main(String[] args) throws IOException {
//        Scanner sc=new Scanner(System.in);
//        FileWriter fileWriter=new FileWriter("d:\\data.txt");
//        String str=sc.nextLine();
//        while(!str.equals("end"))
//        {
//            fileWriter.write(str);
//            fileWriter.write("\n");
//            str=sc.nextLine();
//        }
//        fileWriter.close();
//        String ret;
//        FileReader fileReader=new FileReader("d:\\data.txt");
//        BufferedReader bufferedReader=new BufferedReader(fileReader);
//        while((ret=bufferedReader.readLine())!=null)
//        {
//            System.out.println(ret);
//        }
//        bufferedReader.close();
//        fileReader.close();
//    }
//}
//import java.io.File;
//public class Main {
//    public static void main(String[] args) throws FileNotFoundException {
//        File file=new File("d:\\test.txt");
//        Scanner sc=new Scanner(file);
//        StringBuffer al=new StringBuffer();
//        StringBuffer num=new StringBuffer();
//        while(sc.hasNext())
//        {
//            String ret=sc.nextLine();
//            for(int i=0;i<ret.length();i++)
//            {
//                if(ret.charAt(i)>='0' && ret.charAt(i)<='9')
//                {
//                    num.append(ret.charAt(i));
//                }
//                else{
//                    al.append(ret.charAt(i));
//                }
//            }
//
//        }
//        System.out.println("数字信息："+num.toString());
//        System.out.println("字符信息："+al.toString());
//    }
//}
class Student implements Serializable{
    private String id;
    private String name;
    private String age;
    private String clazz;

    public Student(String id, String name, String age, String clazz) {
        this.id = id;
        this.name = name;
        this.age = age;
        this.clazz = clazz;
    }

    public void setId(String id) {
        this.id = id;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setAge(String age) {
        this.age = age;
    }

    public void setClazz(String clazz) {
        this.clazz = clazz;
    }

    public String getId() {
        return id;
    }

    public String getName() {
        return name;
    }

    public String getAge() {
        return age;
    }

    public String getClazz() {
        return clazz;
    }

    @Override
    public String toString() {
        return "Student{" +
                "id='" + id + '\'' +
                ", name='" + name + '\'' +
                ", age='" + age + '\'' +
                ", clazz='" + clazz + '\'' +
                '}';
    }
}
public class Main {
    public static void main(String[] args) throws IOException, ClassNotFoundException{
        Student[] stu=new Student[2];
        Student s1=new Student("1","张三","18","1");
        Student s2=new Student("2","张四","18","2");
        ObjectOutputStream objectOutputStream=new ObjectOutputStream(new FileOutputStream("d:\\stu.dat"));
        stu[0]=s1;
        stu[1]=s2;
        objectOutputStream.writeObject(stu);
        objectOutputStream.close();
        ObjectInputStream objectInputStream=new ObjectInputStream(new FileInputStream("d:\\stu.dat"));
        Object ob=objectInputStream.readObject();
        if(ob instanceof Student[])
        {
            Student[] raar=(Student[]) ob;
            for(Student tmp:raar){
                System.out.println(tmp);
            }
        }
    }
}
